/**
 * Created by dave on 17/6/8.
 */
var app = new Vue({
    el: '#lookContract',
    data: {
        ctx: '',//根目录
        status: 'adding',
        search: '',
        openId: '',
        adding: true,//待补充
        editing: false,//待修改
        checking: false,//待复审
        Tobesigned: false,//待签署
        statusName: '',
        addingList: [],//待补充list
        checkList: [],//带审核list
        editingList: [],
        tobesignedList: [],
        //记录列表显示的个数
        addingNumber: '',
        editingNumber: '',
        checkingNumber: '',
        tobesignedNumber: ''
    },
    created: function () {
        // this.init();
    },
    mounted: function () {
    },
    methods: {
        //初始化
        init: function () {
            //获取页面中的openID跟applicationId
            this.openId = $("#openId").val();
            var that = this;
            var params = {
                openId:this.openId
            };
            //待签署
            // axios.get(that.ctx + '/wxtest/v2/applications/getTobesignedApplication', {params: params}).then(function(res){
            //     if(res){
            //         that.tobesignedList = res.data;
            //     }
            //     that.tobesignedNumber = that.tobesignedList.length;
            // });

        },
        //search
        labelClick: function () {
            $("#labelClick").css("display","none");
            $('#searchInput').focus();
        },
        inputBlur: function () {
            $("#labelClick").css("display","block");
        },
        searchClick: function () {
            var that = this;
            var params = {
                openId:that.openId
            };
            if(that.status === 'adding'){
                that.addingList = [];
                axios.get(that.ctx + '/wxtest/v2/applications/getUncheckedApplication', {params: params}).then(function(res) {
                    if(res.data){
                        for (var i = 0; i < res.data.length; i++) {
                            var obj = res.data[i];
                            if(that.search === obj.customerName || that.search === obj.phone){
                                that.addingList.push(obj)
                            }
                        }
                    }
                    that.addingNumber = that.addingList.length;
                    if(that.addingList.length === 0){
                        $.toptips("没有查到相应信息");
                    }
                });
                $("#labelClick").css("display","block");
            }
            if(that.status === 'editing'){
                that.editingList = [];
                axios.get(that.ctx + '/wxtest/v2/applications/getReturnedApplication', {params: params}).then(function(res){
                    if(res.data){
                        for (var i = 0; i < res.data.length; i++) {
                            var obj = res.data[i];
                            if(that.search === obj.customerName || that.search === obj.phone){
                                that.editingList.push(obj)
                            }
                        }
                    }
                    that.editingNumber = that.editingList.length;
                    if(that.editingList.length === 0){
                        $.toptips("没有查到相应信息");
                    }
                });
                $("#labelClick").css("display","block");
            }
            if(that.status === 'checking'){
                that.checkList = [];
                axios.get(that.ctx + '/wxtest/v2/applications/getUnconfirmedApplication', {params: params}).then(function(res) {
                    if(res.data){
                        for (var i = 0; i < res.data.length; i++) {
                            var obj = res.data[i];
                            if(that.search === obj.customerName || that.search === obj.phone){
                                that.checkList.push(obj)
                            }
                        }
                    }
                    that.checkingNumber = that.checkList.length;
                    if(that.checkList.length === 0){
                        $.toptips("没有查到相应信息");
                    }
                });
                $("#labelClick").css("display","block");
            }
            if(that.status === 'Tobesigned'){
                that.tobesignedList = [];
                axios.get(that.ctx + '/wxtest/v2/applications/getTobesignedApplication', {params: params}).then(function(res) {
                    if(res.data){
                        for (var i = 0; i < res.data.length; i++) {
                            var obj = res.data[i];
                            if(that.search === obj.customerName || that.search === obj.phone){
                                that.tobesignedList.push(obj)
                            }
                        }
                    }
                    that.tobesignedNumber = that.tobesignedList.length;
                    if(that.tobesignedList.length === 0){
                        $.toptips("没有查到相应信息");
                    }
                });
                $("#labelClick").css("display","block");
            }


        },
        //点击切换
        tabClick: function (a) {
            var that = this;
            if (a === 'adding'){
                this.status = 'adding';
                this.adding = true;
                this.editing = false;
                this.checking = false;
                this.Tobesigned = false;
                this.init();
            }
            if(a === 'editing'){
                this.status = 'editing';
                this.Tobesigned = false;
                this.adding = false;
                this.editing = true;
                this.checking = false;
                var params = {
                    openId:this.openId
                };

                axios.get(that.ctx + '/wxtest/v2/applications/getReturnedApplication', {params: params}).then(function(res){
                    if(res){
                        that.editingList = res.data;
                    }
                    that.editingNumber = that.editingList.length;
                });
            }
            if(a === 'checking'){
                this.status = 'checking';
                this.Tobesigned = false;
                this.adding = false;
                this.editing = false;
                this.checking = true;
                var params = {
                    openId:this.openId
                };
                axios.get(that.ctx + '/wxtest/v2/applications/getUnconfirmedApplication', {params: params}).then(function(res){
                    if(res){
                        that.checkList = res.data;
                    }
                    that.checkingNumber = that.checkList.length;
                });
            }
            if(a === 'Tobesigned'){
                this.status = 'Tobesigned';
                this.adding = false;
                this.editing = false;
                this.checking = false;
                this.Tobesigned = true;
                var params = {
                    openId:this.openId
                };
                axios.get(that.ctx + '/wxtest/v2/applications/getTobesignedApplication', {params: params}).then(function(res){
                    if(res){
                        that.tobesignedList = res.data;
                    }
                    that.tobesignedNumber = that.tobesignedList.length;
                });
            }
        },
        //查看明细
        detailClick: function (a,id) {
            var that = this;
            //待补充,补充资料
            if(a === 'adding'){
                window.location.href = that.ctx + '/agent/application/check/v1/'+id+'?openId='+this.openId+''
            }
            //待修改,补充资料
            if(a === 'editing'){
                window.location.href = that.ctx + '/agent/application/check/v1/'+id+'?openId='+this.openId+''
            }
            //待审核,查看申请详情
            if(a === 'checking'){
                window.location.href = that.ctx + '/agent/application/view/v1/'+id+'?openId='+this.openId+''
            }
            //待签署,查看申请详情
            if(a === 'Tobesigned'){
                window.location.href = that.ctx + '/agent/application/view/v1/'+id+'?openId='+this.openId+''
            }
        }
    }
});
